<?php
/**
 * 权限
 * Enter description here ...
 * @author nijn
 *
 */
class Purview {

	static public function memberPurview() {
		$purview = CHtml::value(Yii::app()->adminUser->group, 'purview');
		return empty($purview) ? array() : $purview;
	}
	
	/**
	 * 返回menu
	 * Enter description here ...
	 */
	static public function menu($config) {
		$purview = self::memberPurview();
		if (empty($purview)) return $config;
		foreach ($config as $key=>$val) {
			if (!in_array($key, $purview)) {
				unset($config[$key]);
			}
		}
		return $config;
	}
	
	/**
	 * 操作判断
	 * Enter description here ...
	 * @param unknown_type $route
	 */
	static public function operate($route) {
		@list($admin,$worker,$module,$controller) = explode('/', $route);
		if (!in_array($worker, array('dealer','operator','provider'))) return true;
		$purview = self::memberPurview();
		if (empty($purview)) return true;
		if (!in_array($module, $purview)) {
			throw new CHttpException(404, '您无权访问');
		}
	}
}

?>